package com.cuz.hot100;

public class Q12IntegerToRomanNumeral {
    public static void main(String[] args) {
//        System.out.println(intToRoman1(3));
//        System.out.println(intToRoman1(4));
//        System.out.println(intToRoman1(9));
//        System.out.println(intToRoman1(58));
        System.out.println(intToRoman1(1994));
    }

    //I             1
    //V             5
    //X             10
    //L             50
    //C             100
    //D             500
    //M             1000
    //1 <= num <= 3999
    public static String intToRoman1(int num) {
        int[] values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        String[] symbols = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        StringBuilder roman = new StringBuilder();
        for (int i = 0; i < values.length; ++i) {
            int value = values[i];
            String symbol = symbols[i];
            while (num >= value) {
                num -= value;
                roman.append(symbol);
            }
            if (num == 0) {
                break;
            }
        }
        return roman.toString();
    }
}
